package com.dianmi.seckill.service.impl;

import com.dianmi.seckill.config.RocketMQConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @author xieqiaofu
 * @date 2021/4/12
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = RocketMQConstant.PAY_PRODUCT_TOPIC, consumerGroup = "pay-order-group")
public class PayOrderConsumer implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt message) {
        byte[] body = message.getBody();
        if (null == body) {
            log.warn("body is null");
            return;
        }
        String json = new String(body, StandardCharsets.UTF_8);
        log.info("delay level: {}", message.getDelayTimeLevel());
        log.info("pay delay data: {}", json);
    }
}
